package com.qf.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * --- 缘分让我们相遇乱世以外 ---
 *
 * @author SJY
 * @date 2024/11/8
 * @desc
 */
@WebFilter("/*")
public class EncodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("--- 开始编码格式过滤 ---" );
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        // 放行到下一个过滤器,如果当前是最后一个,那么下一个就是目标Servlet
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
